const jwt = require("jsonwebtoken")
const { PRIVATE_KEY } = require("../app/config")

class UserController {
  async login(ctx, next) {
    const { id, username } = ctx.user
    const token = jwt.sign({ id, username }, PRIVATE_KEY, {
      expiresIn: 7 * 24 * 60 * 60,
      algorithm: 'RS256'
    })
    ctx.body = { id, username, token }
  }
}

module.exports = new UserController()